package com.lxd.Utils;

import com.lxd.vo.tt;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SpringRabbitListener {
//    @RabbitListener(queues = "hello-queue")
//    public void listenSimpleQueueMessage(String msg) throws InterruptedException {
//        System.out.println("spring 消费者接收到消息：【" + msg + "】");
//    }

//    @RabbitListener(queues = "hello-web")
//    public void helloWeb(String msg) throws InterruptedException {
//        System.out.println("spring 消费者接收到消息hellow eb ：【" + msg + "】");
//    }
//
//    @RabbitListener(queues = "hello-queue")
//    public void listenSimpleQueueMessage2(String msg) throws InterruptedException {
//        System.out.println("spring 消费者1接收到消息：【" + msg + "】");
//        Thread.sleep(20);
//    }
//
//    @RabbitListener(queues = "hello-queue")
//    public void listenSimpleQueueMessage3(String msg) throws InterruptedException {
//        System.out.println("spring 消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(200);
//    }
//
//    @RabbitListener(queues = "fanoutQueue2")
//    public void fanoutQueue2(String msg) throws InterruptedException {
//        System.out.println("fanoutQueue2消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(200);
//    }
//
//    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "fanoutQueue2"),
//            exchange = @Exchange(name = "testfanout1", type = "fanout")))
//    public void fanoutQueue2_2(String msg) throws InterruptedException {
//        System.out.println("fanoutQueue2消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(200);
//    }
////    @RabbitListener(queues = "fanoutQueue1")
////    public void fanoutQueue1(String msg) throws InterruptedException {
////        System.out.println("fanoutQueue1消费者2接收到消息：【" + msg + "】");
////        Thread.sleep(200);
////    }
//    @RabbitListener(bindings=@QueueBinding(value=@Queue(name = "fanoutQueue1"),
//    exchange=@Exchange(name="testfanout1", type="fanout")))
//    public void fanoutQueue1_1(String msg) throws InterruptedException {
//        System.out.println("fanoutQueue1_1消费者2接收到消息：【" + msg + "】");
//        Thread.sleep(200);
//    }

    @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "directqueue1"),
            exchange = @Exchange(name = "testdirectqueue", type = ExchangeTypes.DIRECT)
            , key = "red"))
    public void direct1(tt msg) throws InterruptedException {
        System.out.println("fdirect1接收到消息：【" + msg.getName() + "】");

    }
}
